home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / local / ch_local.c next >
Encoding:
C/C++ Source or Header  |  1988-03-28  |  4.0 KB  |  136 lines

  1. /*
  2.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  3.  *     
  4.  *
  5.  *     Copyright (C) 1979,1980,1981  University of Delaware
  6.  *     
  7.  *     Department of Electrical Engineering
  8.  *     University of Delaware
  9.  *     Newark, Delaware  19711
  10.  *
  11.  *     Phone:  (302) 738-1163
  12.  *     
  13.  *     
  14.  *     This program module was developed as part of the University
  15.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  16.  *     
  17.  *     Acquisition, use, and distribution of this module and its listings
  18.  *     are subject restricted to the terms of a license agreement.
  19.  *     Documents describing systems using this module must cite its source.
  20.  *
  21.  *     The above statements must be retained with all copies of this
  22.  *     program and may not be removed without the consent of the
  23.  *     University of Delaware.
  24.  *     
  25.  *
  26.  *     version  -1    David H. Crocker    March   1979
  27.  *     version   0    David H. Crocker    April   1980
  28.  *     version  v7    David H. Crocker    May     1981
  29.  *     version   1    David H. Crocker    October 1981
  30.  *
  31.  */
  32.  
  33. #include "util.h"
  34. #include "mmdf.h"
  35. #include <signal.h>
  36. #include "ch.h"
  37. #include "phs.h"
  38.  
  39. extern Chan    *ch_nm2struct();
  40. extern LLog *logptr;
  41.  
  42. Chan    *chanptr;
  43.  
  44. /*
  45.  *  CH_LOCAL --  Actual delivery of mail, out of transport environment
  46.  *
  47.  *  lo_wtmail does most of the interesting work.  qu2lo_send handles the
  48.  *  deliver interface and the verification. Lo_wtmail handles all the piping
  49.  *  filing, and the maildelivery stuff and looks after return values etc.
  50.  *
  51.  *  in any event, this process runs setuid to root.  for each recipient, it
  52.  *  determines the uid, etc, and then forks a child to do the actual work
  53.  *  (do the parsing of files etc).The child does a setuid
  54.  *  to the recipient.  the parent version of the process just waits for the
  55.  *  child to complete.  its job is to a) acquire the next address, b) get
  56.  *  the recipient id info, and c) fork and wait on the child.
  57.  */
  58.  
  59. /*      MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN     */
  60.  
  61. main (argc, argv)
  62. int     argc;
  63. char   *argv[];
  64. {
  65.     extern char *dupfpath ();
  66.     short retval;
  67.     int   realid,
  68.       effecid;
  69.  
  70.     mmdf_init (argv[0]);
  71.     siginit ();
  72.     signal (SIGINT, SIG_IGN);   /* always ignore interrupts             */
  73.  
  74.     if ((chanptr = ch_nm2struct (argv[0])) == (Chan *) NOTOK)
  75.     {
  76.     ll_log (logptr, LLOGTMP, "qu2lo_send (%s) unknown channel", argv[0]);
  77.     exit (NOTOK);
  78.     }
  79.  
  80.     getwho (&realid, &effecid);
  81.     if (effecid != 0)              /* MUST run as superuser              */
  82.     err_abrt (RP_BHST, "not running as superuser");
  83.  
  84.     retval = ch_local (argc, argv);
  85.     ll_close (logptr);              /* clean log end, if cycled  */
  86.     exit (retval);
  87. }
  88. /* **************  (ch_) LOCAL MAIL DELIVERY  ************************ */
  89.  
  90. ch_local (argc, argv)          /* send to local machine               */
  91. int     argc;
  92. char   *argv[];
  93. {
  94.     ch_llinit (chanptr);
  95. #ifdef DEBUG
  96.     ll_log (logptr, LLOGBTR, "ch_local ()");
  97. #endif
  98.  
  99.     if (rp_isbad (qu_init (argc, argv)))
  100.     return (RP_NO);          /* problem setting-up for deliver     */
  101.     phs_note (chanptr, PHS_CNSTRT);         /* make a timestamp */
  102.     phs_note (chanptr, PHS_CNGOT);         /* make a timestamp */
  103.  
  104.     if (rp_isbad (qu2lo_send ()))
  105.     return (RP_NO);          /* send the batch of outgoing mail    */
  106.  
  107.     qu_end (OK);                  /* done with Deliver function         */
  108.     phs_note  (chanptr, PHS_CNEND);     /* note end of session */
  109.  
  110.     return (RP_OK);          /* NORMAL RETURN                      */
  111. }
  112.  
  113.  
  114. /* VARARGS2 */
  115. err_abrt (code, fmt, b, c, d)     /* terminate ourself                  */
  116. short     code;
  117. char    *fmt, *b, *c, *d;
  118. {
  119.     char linebuf[LINESIZE];
  120.  
  121.     qu_end (NOTOK);
  122.     if (rp_isbad (code))
  123.     {
  124.     if (rp_gbval (code) == RP_BNO || logptr -> ll_level >= LLOGBTR)
  125.     {                         /* don't worry about minor stuff      */
  126.         sprintf (linebuf, "%s%s", "err [ ABEND (%s) ]\t", fmt);
  127.         ll_log (logptr, LLOGFAT, linebuf, rp_valstr (code), b, c, d);
  128. #ifdef DEBUG
  129.         abort ();
  130. #endif
  131.     }
  132.     }
  133.     ll_close (logptr);           /* in case of cycling, close neatly   */
  134.     exit (code);
  135. }
  136.